package com.ishare.api.controller;

import com.ishare.api.po.login.*;
import com.ishare.api.service.face.LoginFaceService;
import com.ishare.api.vo.login.RepeatedRegisterVo;
import com.ishare.api.vo.user.UserVo;
import com.ishare.common.dto.VoData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 李嘉宾
 * @since 1.0.0
 */
@RestController
@Api(tags = {"用户登陆注册相关"})
@RequestMapping("/api/user/login")
public class LoginController {

    @Resource
    private LoginFaceService loginFaceService;

    @PostMapping("/loginSubmit")
    @ApiOperation(value = "用户登陆提交")
    public VoData<UserVo> loginSubmit(@Validated @RequestBody UserLoginParam param){
        UserVo userVo = loginFaceService.loginSubmit(param);
        return VoData.success(userVo);
    }

    @PostMapping("/registerSubmit")
    @ApiOperation(value = "用户注册提交")
    public VoData<UserVo> registerSubmit(@Validated @RequestBody UserRegisterParam userRegisterParam){
        UserVo userVo = loginFaceService.registerSubmit(userRegisterParam);
        return VoData.success(userVo);
    }

    @PostMapping("/getEmailCode")
    @ApiOperation(value = "用户获取邮箱验证码提交")
    public VoData<Void> getEmailCode(@Validated @RequestBody UserGetEmailCodeParam userGetEmailCodeParam){
        loginFaceService.sendEmailCode(userGetEmailCodeParam);
        return VoData.success();
    }

    @PostMapping("/checkEmailRepeated")
    @ApiOperation(value = "校验邮箱是否重复")
    public VoData<RepeatedRegisterVo> checkEmailRepeated(@Validated @RequestBody CheckEmailRepeatedRegisterParam checkEmailRepeatedRegisterParam){
        return VoData.success(loginFaceService.checkEmailIsRepeated(checkEmailRepeatedRegisterParam));
    }

    @PostMapping("/checkUserNameRepeated")
    @ApiOperation(value = "校验用户名是否重复")
    public VoData<RepeatedRegisterVo> checkUserNameRepeated(@Validated @RequestBody CheckUserNameRepeatedRegisterParam checkUserNameRepeatedRegisterParam){
        return VoData.success(loginFaceService.checkUserNameIsRepeated(checkUserNameRepeatedRegisterParam));
    }

}
